<script setup lang="ts">
const props = withDefaults(
  defineProps<{
    modelValue: boolean
  }>(),
  {
    modelValue: false
  }
)
const emit = defineEmits<{
  (el: 'update:modelValue', value: boolean): void
  (el: 'change'): void
}>()
// 点击复选框
const changeChecked = () => {
  emit('update:modelValue', !props.modelValue)
  emit('change')
}
</script>

<template>
  <div class="xtx-checkbox" @click="changeChecked">
    <i v-if="modelValue" class="iconfont icon-checked"></i>
    <i v-else class="iconfont icon-unchecked"></i>
    <!-- 判断插槽有没有内容，无内容的话不渲染span标签 -->
    <span v-if="$slots.default"><slot /></span>
  </div>
</template>

<style scoped lang="less">
.xtx-checkbox {
  display: inline-block;
  margin-right: 2px;
  .icon-checked {
    color: @xtxColor;
    ~ span {
      color: @xtxColor;
    }
  }
  i {
    position: relative;
    top: 1px;
  }
  span {
    margin-left: 2px;
  }
}
</style>
